package com.ruoyi.system.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QService;
import com.ruoyi.system.service.IQServiceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务对话列Controller
 * 
 * @author ruoyi
 * @date 2024-06-20
 */
@Controller
@RequestMapping("/system/service")
public class QServiceController extends BaseController
{
    private String prefix = "system/service";

    @Autowired
    private IQServiceService qServiceService;

  //  @RequiresPermissions("system:service:view")
    @GetMapping()
    public String service()
    {
        return prefix + "/service";
    }

    @GetMapping("/servicetel")
    public String servicetel()
    {
        return prefix + "/servicetel";
    }

    @GetMapping("/serviceim")
    public String serviceim()
    {
        return prefix + "/serviceim";
    }

    @GetMapping("/servicewjt")
    public String servicewjt()
    {
        return prefix + "/servicewjt";
    }


    @GetMapping("/chatRecord")
    public String selectRelative() {
        return prefix + "/chatRecord";
    }

    /**
     * 查询服务对话列列表
     */
  //  @RequiresPermissions("system:service:list")
    @PostMapping("/listTel")
    @ResponseBody
    public TableDataInfo listTel(QService qService)
    {
        qService.setServicetype("5");
        startPage();
        List<QService> list = qServiceService.selectQServiceList(qService);
        return getDataTable(list);

    }

    @CrossOrigin
    @PostMapping("/listTelNomanyiYiban")
    @ResponseBody
    public TableDataInfo listTelNomanyiYiban(QService qService)
    {
        qService.setServicetype("5");
        startPage();
        List<QService> list = qServiceService.selectQServiceListNomanyiYiban(qService);
        return getDataTable(list);

    }


    @CrossOrigin
    @PostMapping("/listTelNomanyi")
    @ResponseBody
    public TableDataInfo listTelNomanyi(QService qService)
    {
        qService.setServicetype("5");
        startPage();
        List<QService> list = qServiceService.selectQServiceListNomanyi(qService);
        return getDataTable(list);

    }

    @PostMapping("/listIM")
    @ResponseBody
    public TableDataInfo listIM(QService qService)
    {
          qService.setServicetype("6");
        startPage();
        List<QService> list = qServiceService.selectQServiceList(qService);
        return getDataTable(list);

    }

    /**
     * 查询服务对话列列表
     */
  //  @RequiresPermissions("system:service:list")
    @PostMapping("/listmyd")
    @ResponseBody
    public TableDataInfo listmyd(  QService qService)
    {

        startPage();
        List<QService> list = qServiceService.selectQServiceListForbmy(qService);
        return getDataTable(list);
    }


    /**
     * 查询服务未接通对话列列表
     */
   // @RequiresPermissions("system:service:list")
    @PostMapping("/listwjt/{state}")
    @ResponseBody
    public TableDataInfo listwjt(@PathVariable("state")  String state ,  QService qService)
    {
        qService.setState(state);
        startPage();
        List<QService> list = qServiceService.selectQServiceList(qService);
        return getDataTable(list);
    }

    /**
     * 导出服务对话列列表
     */
   // @RequiresPermissions("system:service:export")
    @Log(title = "服务对话列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QService qService)
    {
        List<QService> list = qServiceService.selectQServiceList(qService);
        ExcelUtil<QService> util = new ExcelUtil<QService>(QService.class);
        return util.exportExcel(list, "服务对话列数据");
    }

    /**
     * 新增服务对话列
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存服务对话列
     */
  //  @RequiresPermissions("system:service:add")
    @Log(title = "服务对话列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QService qService)
    {
        return toAjax(qServiceService.insertQService(qService));
    }

    /**
     * 修改服务对话列
     */
   // @RequiresPermissions("system:service:edit")
    @GetMapping("/edit/{serviceId}")
    public String edit(@PathVariable("serviceId") String serviceId, ModelMap mmap)
    {
        QService qService = qServiceService.selectQServiceByServiceId(serviceId);
        mmap.put("qService", qService);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务对话列
     */
   // @RequiresPermissions("system:service:edit")
    @Log(title = "服务对话列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QService qService)
    {
        return toAjax(qServiceService.updateQService(qService));
    }

    /**
     * 删除服务对话列
     */
   // @RequiresPermissions("system:service:remove")
    @Log(title = "服务对话列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qServiceService.deleteQServiceByServiceIds(ids));
    }
}
